package com.example.aggregation.shardingdemo.controller;


import com.example.aggregation.shardingdemo.entity.Providers;
import com.example.aggregation.shardingdemo.entity.Temp;
import com.example.aggregation.shardingdemo.mapper.ProvidersMapper;
import com.example.aggregation.shardingdemo.mapper.TempMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/sharding")
@Slf4j
public class ProviderController {

    @Autowired
    private ProvidersMapper providersMapper;
    @Autowired
    private TempMapper tempMapper;

    @GetMapping("/testSharding")
    @Transactional
    @ShardingTransactionType(value = TransactionType.BASE)
    public void testSharding() {
        tempMapper.insert(new Temp("dfeter"));
        int x=1/0;
        providersMapper.insert(new Providers("p002","fuwu",new Date()));
    }
}
